<style lang="scss">
	@import '@/common/uni-ui.scss';

	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #FFFFFF;
		min-height: 100%;
		height: auto;
		padding: 16rpx;
	}
	.content {
		padding-top: 120rpx;
	}
	.list-picture {
		width: 100%;
		height: 145px;
	}

	.thumb-image {
		width: 100%;
		height: 100%;
	}
	.top-bar {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		background-color: #FFFFFF;
		width: 100%;
		.top-menu{
			display: flex;
			flex-direction: row;
			flex-wrap: nowrap;
			padding: 16rpx;
			.menu-item {
				display: flex;
				flex-direction: column;
				flex-wrap: nowrap;
				align-items: center;
				color: $uni-text-color-grey;
				margin: 0 16rpx;
				&.active{
					color: $uni-text-color;
					&::after{
						content: '';
						width: 40rpx;
						border: 1px solid $uni-color-primary;
					}
				}
			}
		}
	}
</style>
<template>
	<view class="content">
		<view class="top-bar">
			<uni-search-bar @confirm="confirm" @clear="clear" @cancel="clear" placeholder="搜索联系人或手机号" v-model="pagerequest.title" />
		</view>
		<group-list :list="groupBuys"></group-list>
		<uni-load-more :status="status"></uni-load-more>
	</view>
</template>

<script>
	import groupList from '../../components/group-list.vue'
	export default {
		components:{
			groupList
		},
		data() {
			return {
				groupBuys: [],
				pagerequest: {
					maxResultCount: 20,
					skipCount: 0,
					sorting: 'id desc',
					title:'',
					linkMan:'',
					phoneNumber: '',
					isActive: true
				},
				status: 'more'
			};
		},
		onLoad(option) {
			this.getpage();
		},
		onReachBottom() {
			this.getpage();
		},
		onPullDownRefresh() {
			this.groupBuys = [];
			this.getpage();
		},
		methods: {
			getpage() {
				this.status = 'loading';
				this.pagerequest.skipCount = this.groupBuys.length;
				
				if (/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.pagerequest.title)) {
					this.pagerequest.phoneNumber = this.pagerequest.title;
				} else {
					this.pagerequest.linkMan = this.pagerequest.title;
				}
				
				this.$http.get("/api/services/app/GroupBuy/GetAll", {
					params: this.pagerequest
				}).then(res => {
					this.groupBuys = this.groupBuys.concat(res.data.result.items);
					if (res.data.result.totalCount == this.groupBuys.length) {
						this.status = "noMore";
					} else {
						this.status = "more";
					}
					uni.stopPullDownRefresh();
				});
			},
			confirm() {
				this.groupBuys = [];
				console.log(this.pagerequest);
				this.getpage();
			},
			clear(){
				this.pagerequest.linkMan = '';
				this.pagerequest.title = '';
				this.pagerequest.phoneNumber = '';
				this.groupBuys = [];
				this.getpage();
			}
		}
	}
</script>
